home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / gdb-4.12 / sim / h8500 / run.c < prev   
Encoding:
C/C++ Source or Header  |  1994-02-03  |  2.1 KB  |  107 lines

  1. /* run front end support for H8/500
  2.    Copyright (C) 1987, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of H8300 SIM
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* Steve Chamberlain
  22.    sac@cygnus.com */
  23.  
  24. #include <stdio.h>
  25. #include "../../bfd/bfd.h"
  26. #include "sysdep.h"
  27.  
  28. int
  29. main (ac, av)
  30.      int ac;
  31.      char **av;
  32. {
  33.   bfd *abfd;
  34.   bfd_vma start_address;
  35.   asection *s;
  36.   int i;
  37.   int verbose = 0;
  38.   int trace = 0;
  39.   char *name = "";
  40.   for (i = 1; i < ac; i++)
  41.     {
  42.       if (strcmp (av[i], "-v") == 0)
  43.     {
  44.       verbose = 1;
  45.     }
  46.       else if (strcmp (av[i], "-t") == 0)
  47.     {
  48.       trace = 1;
  49.     }
  50.       else if (strcmp (av[i], "-c") == 0)
  51.     {
  52.       int csize;
  53.       csize = atoi (av[i + 1]);
  54.       sim_csize (csize);
  55.       i++;
  56.     }
  57.       else
  58.     {
  59.       name = av[i];
  60.     }
  61.     }
  62.   if (verbose)
  63.     {
  64.       printf ("run %s\n", name);
  65.     }
  66.   abfd = bfd_openr (name, "coff-h8500");
  67.   if (abfd)
  68.     {
  69.  
  70.       if (bfd_check_format (abfd, bfd_object))
  71.     {
  72.  
  73.       for (s = abfd->sections; s; s = s->next)
  74.         {
  75.           unsigned char *buffer = malloc (bfd_section_size (abfd, s));
  76.           bfd_get_section_contents (abfd,
  77.                     s,
  78.                     buffer,
  79.                     0,
  80.                     bfd_section_size (abfd, s));
  81.           sim_write (s->vma, buffer, bfd_section_size (abfd, s));
  82.         }
  83.  
  84.       start_address = bfd_get_start_address (abfd);
  85.       sim_set_pc (start_address);
  86.       if (trace)
  87.         {
  88.           int done = 0;
  89.           while (!done)
  90.         {
  91.           done = sim_trace ();
  92.         }
  93.         }
  94.       else
  95.         {
  96.           sim_resume (0, 0);
  97.         }
  98.       if (verbose)
  99.         sim_info (printf, 0);
  100.  
  101.       return 0;
  102.     }
  103.     }
  104.  
  105.   return 1;
  106. }
  107.